package cn.gson.springboot.model.pojos;

import javax.persistence.*;
import java.util.Collection;
import java.util.List;
import java.util.Objects;

@Entity
@Table(name = "department_", schema = "crm")
public class Department {
    private int deptId;
    private String deptName;
    private Integer manageId;
    private List<Job> jobs;
    private Collection<Maintenance> maintenancesByDeptId;
    private List<FunctionType> functionType;
    private List<Employee> employeeByDeptId;

    @ManyToMany(cascade = CascadeType.ALL)
    @JoinTable(name = "department_function_type",
            joinColumns = {
                    @JoinColumn(name = "dept_id")
            },
            inverseJoinColumns = {
                    @JoinColumn(name = "fun_type_id")
            })
    public List<FunctionType> getFunctionType() {
        return functionType;
    }

    public void setFunctionType(List<FunctionType> functionType) {
        this.functionType = functionType;
    }

    @Id
    @Column(name = "dept_id", nullable = false)
    public int getDeptId() {
        return deptId;
    }

    public void setDeptId(int deptId) {
        this.deptId = deptId;
    }

    @Basic
    @Column(name = "dept_name", nullable = true, length = 255)
    public String getDeptName() {
        return deptName;
    }

    public void setDeptName(String deptName) {
        this.deptName = deptName;
    }

    @Basic
    @Column(name = "manage_id", nullable = true)
    public Integer getManageId() {
        return manageId;
    }

    public void setManageId(Integer manageId) {
        this.manageId = manageId;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Department that = (Department) o;
        return deptId == that.deptId &&
                Objects.equals(deptName, that.deptName) &&
                Objects.equals(manageId, that.manageId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(deptId, deptName, manageId);
    }

    @OneToMany(mappedBy = "departmentByDeptId",cascade = CascadeType.ALL)
    public Collection<Maintenance> getMaintenancesByDeptId() {
        return maintenancesByDeptId;
    }

    public void setMaintenancesByDeptId(Collection<Maintenance> maintenancesByDeptId) {
        this.maintenancesByDeptId = maintenancesByDeptId;
    }

    @OneToMany(mappedBy = "department",cascade = CascadeType.ALL)
    public List<Job> getJobs() {
        return jobs;
    }

    public void setJobs(List<Job> jobs) {
        this.jobs = jobs;
    }

    @OneToMany(mappedBy = "department",cascade = CascadeType.ALL)
    public List<Employee> getEmployeeByDeptId() {
        return employeeByDeptId;
    }

    public void setEmployeeByDeptId(List<Employee> employeeByDeptId) {
        this.employeeByDeptId = employeeByDeptId;
    }




    @Override
    public String toString() {
        return "Department{" +
                "deptId=" + deptId +
                ", deptName='" + deptName + '\'' +
                ", manageId=" + manageId +
                '}';
    }
}
